import pygame
from random import randrange
from itertools import count
from pygame.locals import KEYDOWN, K_UP, K_RIGHT, K_DOWN, K_LEFT, QUIT, K_r, K_q

pygame.init()
width,height = 480, 480
screen = pygame.display.set_mode((width,height))
clock = pygame.time.Clock()
up, right, down, left = (0, -10), (10, 0), (0, 10), (-10, 0)
snake = [pygame.Rect(10, 10 + value * 10, 10, 10) for value in range(20)]
snake_dir, food, dead = down, None, False


for counter in count():
    clock.tick(min(5 + (len(snake) / 4), 30))

    
    next = snake[-1].move(snake_dir)
    snake.append(next)
    del snake[0]
    screen.fill((0,0,0))
    for rect in snake:
        pygame.draw.rect(screen,(255,255,255),rect)
    
    pygame.display.flip()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit(0)
